<?php

namespace Drupal\wx_transfers\Entity;

use Drupal\wx_transfers\ViewsController\Traits\WxTransfersCheckNameTrait;
use Drupal\wx_transfers\ViewsController\Traits\WxTransfersStatusTrait;
use Entity;

class WxTransfers extends Entity {

  public $id;

  public $vid;

  public $uid;

  public $op_uid;

  public $created;

  public $changed;

  public $is_new_revision;

  public $module;

  public $attach;

  public $appid;

  public $mch_id;

  public $openid;

  public $partner_trade_no;

  public $check_name = 0;

  public $re_user_name;

  public $amount;

  public $note;

  public $status = 0;

  public $retry = 5;

  public $next_retry;

  public $err_code;

  public $err_code_des;

  public $payment_no;

  public $payment_time;

  use WxTransfersCheckNameTrait, WxTransfersStatusTrait;

  function __construct($values = []) {
    $this->is_new_revision = TRUE;
    parent::__construct($values, 'wx_transfers');
  }

  public function save() {
    $this->changed = REQUEST_TIME;
    if (empty($this->created)) {
      $this->created = REQUEST_TIME;
    }

    $this->op_uid = $GLOBALS['user']->uid;
    if (empty($this->uid)) {
      $this->uid = $GLOBALS['user']->uid;
    }

    return parent::save();
  }

}
